Skip to content

Conversation

@sebersole
Copy link
Member

HHH-19216 - NamedEntityGraph annotation supporting Hibernate parseable format


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@sebersole sebersole marked this pull request as draft March 3, 2025 13:15
* @apiNote Entity-name is used here rather than entity-class to allow
* for dynamic models.
*/
String rootEntityName() default "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if there was a way to specify this as part of the mini-language itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets a little tricky. Syntactically what is the difference between MyEntity( someAttribute ) and someAttribute( someSubAttribute )?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like MyEntity: someAttribute

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan was to simply have this pass through GraphParser. So if you are asking me if I want to change the GraphParser grammar, no not really.

If we don't change GraphParser, there would need to be a pre-analysis of this text to determine if there is a =n entity "prefix". I'm not against it, just not sure what it gains us. But if others think its "nicer", I'm fine with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should mention, I had planned to change this a bit to allow either name or class:

@interface NamedEntityGraph {
    ...
    String rootEntityName() default "";
    Class<?> rootEntityType() default void.class;

Mainly because I know most users will prefer to use the class reference. I will agree that given just #rootEntityName your suggestion is nice.

6 in one, half dozen in the other imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like MyEntity: someAttribute

So I did end up adding this to the parser syntax. But in practice, for the named graphs, this is only needed for package-level definition. For entity-level I just required that the annotation be placed on the root entity for the graph (in keeping with JPA variant) and so we always know the entity type there.

@Entity
@NamedEntityGraph( graph="title, isbn")
class Book {...}
@NamedEntityGraph( name="book-title-isbn", graph="Book: title, isbn")
package org.hibernate.test;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For entity-level I just required that the annotation be placed on the root entity for the graph (in keeping with JPA variant) and so we always know the entity type there.

Perfect!

Comment on lines 53 to 54
@NamedEntityGraph( name = "test-id-name", graph = "(id, name)" )
@NamedEntityGraph( name = "test-id-name-parent", graph = "(id, name, parent)" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed nice.

@sebersole sebersole force-pushed the named-entity-graph branch from 56f9d3b to 104edf2 Compare March 7, 2025 14:32
@sebersole sebersole marked this pull request as ready for review March 7, 2025 15:56
@sebersole sebersole force-pushed the named-entity-graph branch from e0f848b to 7da9f64 Compare March 7, 2025 16:15
@sebersole sebersole force-pushed the named-entity-graph branch 2 times, most recently from f827d8f to 0ea5bd8 Compare March 7, 2025 16:52
…e format

HHH-19237 - Expand graph language to optionally specify entity
HHH-19217 - Expose GraphParser#parse on SessionFactory
@sebersole sebersole force-pushed the named-entity-graph branch from eab7539 to 790774e Compare March 10, 2025 16:52
@sebersole sebersole merged commit 1a908ea into hibernate:main Mar 10, 2025
5 of 8 checks passed
@sebersole sebersole deleted the named-entity-graph branch March 10, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants